<?php

/**
 * Subclass for representing a row from the 'faq_items' table.
 *
 * 
 *
 * @package lib.model
 */ 
class FaqItems extends BaseFaqItems
{
	protected $_FaqCategory = null;
	protected $_count;
    public function getFaqCategory()
    {
    	$this->_FaqCategory = FaqCategoriesPeer::retrieveByPK($this->getCatId());
    	
    	if (!$this->_FaqCategory)
    	{
    		$this->_FaqCategory = new FaqCategories();
    		$this->_FaqCategory->setId($this->getCatId());
		}
    	
    	return $this->_FaqCategory;
	}
	
	public function getcount()
	{
		$c = new Criteria();
		$c->add(FaqItemsPeer::PARENT_ID,$this->getId());
		$this->_count = FaqItemsPeer::doCount($c);
		return $this->_count;
	}
	
	public function delete($con = null)
	{
		$con = new MysqlDAL('propel');
		$sql = "SELECT COUNT(*) AS total FROM faq_items WHERE parent_id = '{$this->getId()}'";
		$res = $con->doSelect($sql);
		if($res[0]['total'] > 0){
			return false;
		}else{
		 	parent::delete();
		 	return true;
		}
	}
}
